Skip to content

fix: replace - and . with _ in generated C header #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025

Conversation

jordancarlin
Copy link
Contributor

@jordancarlin jordancarlin commented Jul 12, 2025

- and . are not legal in the name of a #define in C. This replaces - and . with _ in CSR and exception code names in the generated C header, as is already done for instruction names.

Currently, invalid examples are emitted in the "C header" (gen/c_header/encoding.out.h) generated via ./do gen:c_header, for example:

#define CSR_MSTATUSH.RV32 0x310
#define CSR_MEDELEGH.RV32 0x312
#define CSR_MENVCFGH.RV32 0x31a
[...]
#define CAUSE_ENVIRONMENT_CALL_FROM_VS-MODE 0xa
#define CAUSE_ENVIRONMENT_CALL_FROM_M-MODE 0xb

With proposed changes:

#define CSR_MSTATUSH_RV32 0x310
#define CSR_MEDELEGH_RV32 0x312
#define CSR_MENVCFGH_RV32 0x31a
[...]
#define CAUSE_ENVIRONMENT_CALL_FROM_VS_MODE 0xa
#define CAUSE_ENVIRONMENT_CALL_FROM_M_MODE 0xb

`-` and `.` are not legal in the name of a `#define` in C. This replaces `-`
and `.` with `_` in CSR and exception code names in the generated C header,
as is already done for instruction names.
Copy link

codecov bot commented Jul 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.30%. Comparing base (1ff5df5) to head (a119a16).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #895   +/-   ##
=======================================
  Coverage   43.30%   43.30%           
=======================================
  Files          10       10           
  Lines        4787     4787           
  Branches     1298     1298           
=======================================
  Hits         2073     2073           
  Misses       2714     2714           
Flag Coverage Δ
idlc 43.30% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@dhower-qc dhower-qc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@dhower-qc dhower-qc requested a review from AFOliveira July 14, 2025 15:09
@ThinkOpenly
Copy link
Collaborator

It would be nice to before/after examples in the commit/PR message. I was going to add them, but I just haven't gotten to it, yet.

@ThinkOpenly
Copy link
Collaborator

Currently, invalid examples are emitted in the "C header" (gen/c_header/encoding.out.h) generated via ./do gen:c_header, for example:

#define CSR_MSTATUSH.RV32 0x310
#define CSR_MEDELEGH.RV32 0x312
#define CSR_MENVCFGH.RV32 0x31a
[...]
#define CAUSE_ENVIRONMENT_CALL_FROM_VS-MODE 0xa
#define CAUSE_ENVIRONMENT_CALL_FROM_M-MODE 0xb

With proposed changes:

#define CSR_MSTATUSH_RV32 0x310
#define CSR_MEDELEGH_RV32 0x312
#define CSR_MENVCFGH_RV32 0x31a
[...]
#define CAUSE_ENVIRONMENT_CALL_FROM_VS_MODE 0xa
#define CAUSE_ENVIRONMENT_CALL_FROM_M_MODE 0xb

Copy link
Collaborator

@ThinkOpenly ThinkOpenly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR message. (I hope that's OK.)

@jordancarlin
Copy link
Contributor Author

I updated the PR message. (I hope that's OK.)

Perfect. Thanks @ThinkOpenly!

@AFOliveira
Copy link
Collaborator

I must have fixed this on instructions and forgot the rest. Thanks!

@AFOliveira AFOliveira added this pull request to the merge queue Jul 16, 2025
Merged via the queue into riscv-software-src:main with commit be0871b Jul 16, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants